﻿//chk = function (tblid, id, type) {
//    var count = 1
//    var countchk = 0
//    var ele = document.getElementById(tblid).getElementsByTagName("input");
//    for (var i = 0; i < ele.length; i++) {
//        if (ele[i].type == "checkbox") {
//            countchk += 1;
//            if (type == "master") {
//                if (document.getElementById(id).checked == true) {
//                    ele[i].checked = true;
//                }
//                else {
//                    ele[i].checked = false;
//                }
//            }
//            else {
//                if (ele[i].checked == true) {
//                    count += 1;
//                }
//            }
//        }
//    }
//    if (type == "child") {
//        for (var i = 0; i < ele.length; i++) {
//            if (ele[i].type == "checkbox") {
//                if (count == countchk) {
//                    ele[0].checked = true;
//                    break;
//                }
//                else {
//                    ele[0].checked = false;
//                    break;

//                }
//            }
//        }

//    }
//}


chk = function (tblid, id, type) {
    var count = 0
    var countchk = 0
    var ele = document.getElementById(tblid).getElementsByTagName("input");
    if (type == "master") {
        for (var i = 0; i < ele.length; i++) {
            if (ele[i].type == "checkbox") {
                if (document.getElementById(id).checked == true) { if (!ele[i].disabled) { ele[i].checked = true; } }
                else { ele[i].checked = false; }
            }
        }
    }
    if (type == "child") {
        for (var i = 1; i < ele.length; i++) {
            if (ele[i].type == "checkbox") {
                countchk += 1;
                if (ele[i].checked == true) {
                    count += 1;
                }
            }
        }
        if (count == countchk) {
            ele[0].checked = true;

        }
        else {
            ele[0].checked = false;


        }

    }
    clearlb();
}
upload = function () {
    document.getElementById('<%=ImgItem.ClientId %>').src = document.getElementById('<%=upldImage.ClientId %>').value;
}

function stopDefault(e) /* COde For Stop the Default Behavior of Button */
{
    if (e && e.preventDefault) {
        e.preventDefault();
    }
    else {
        window.event.returnValue = false;
    }
}

function stopParentDefault(e) {
    if (e.stopPropogation) {
        e.stopPropogation();
    }
    else {
        e.cancelBubble = true;
    }
}

function fixChar(obj,len1) {
        var len = obj.value.length;
        if (len == 0 || len == '' || len == 'undefined') {
            len = 0;
        }
        if (len > len1) {
            alert('Maximum length reached!');
            obj.value = obj.value.substring(0, len1);
        }

    }
    function chkDelete(tblid, delarg) {
        var eleTBL = document.getElementById(tblid);
        var count = 0;
        if (eleTBL) {
            var input = eleTBL.getElementsByTagName("input");
            for (var i = 0; i < input.length; i++) {
                if (input[i].type == "checkbox") {
                    if (input[i].checked == true) {
                        count += 1;
                    
                    }
                }
            } 
        }
        if (count == 0) {
            alert("Please select at least one record for delete/remove!");
            return false;
        }
        else {
            var delArg = 'Are you sure you want to remove selected record(s)?';
            if (delarg == "delete") {
                delArg = 'Are you sure you want to delete selected record(s)?'
            }
            if (confirm(delArg)) {
                return true;
            }
            else {
                return false;
            }
        }

    }


    function findChecked(tblid) {
        var eleTBL = document.getElementById(tblid);
        var count = 0;
        if (eleTBL) {
            var input = eleTBL.getElementsByTagName("input");
            for (var i = 1; i < input.length; i++) {
                if (input[i].type == "checkbox") {
                    if (input[i].checked == true) {
                        count += 1;
                    }
                }
            }
        }
        if (count == 0) {
            alert("Please select at least one record !");
            return false;
        }
       
    }


    clearlb = function () {
        if (document.getElementById('ctl00_CP1_lbMsg')) {
            document.getElementById('ctl00_CP1_lbMsg').innerHTML = '';
        }
        else if (document.getElementById('ctl00_CP1_lbmsg')) {
            document.getElementById('ctl00_CP1_lbmsg').innerHTML = '';
        }
    }
   // document.addEventListener('click',clearlb(), true);

